﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class NewsFavourate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 程序代码
        BZZ.DataAcess woker = new BZZ.DataAcess();
        BZZ.CommonFunctions cf = new BZZ.CommonFunctions();
        string cataid = "3";
        string sql = "select * from news where cataid=" + cataid + " order by id desc";
        DataSet dset = woker.Execute(sql);

        #region get page para
        string p = Request["p"];
        int CurrentPageNum = 1;
        try
        {
            CurrentPageNum = Convert.ToInt16(p);
        }
        catch { CurrentPageNum = 1; }
        if (CurrentPageNum == 0) CurrentPageNum++;
        int recordCount = dset.Tables[0].Rows.Count;
        int pageSize = 20;
        string para = "cmd=list&cataid=" + cataid;
        //Response.Write("p=" + CurrentPageNum.ToString() + ",count=" + recordCount.ToString());
        //Response.End();
        #endregion

        #region 获取新闻数据
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("				  <table width=\"680\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"zt07\">");
        sb.Append("                  <tr>");
        sb.Append("                    <td height=\"10\" colspan=\"2\" align=\"left\" valign=\"top\">					</td>");
        sb.Append("                    </tr>");
        for (int i = (CurrentPageNum - 1) * pageSize; i < recordCount && i < CurrentPageNum * pageSize; i++)
        {
            #region get data
            DataRow r = dset.Tables[0].Rows[i];
            string title = r["title"].ToString();
            string id = r["id"].ToString();
            string pubDate = Convert.ToDateTime(r["pubdate"]).ToString("yyyy-MM-dd");

            sb.Append("                  <tr>");
            sb.Append("                    <td align=\"left\" valign=\"top\" class=\"zt07\">·<a href='NewsDetail.aspx?id=" + id.ToString() + "&cataid=" + cataid + "'>" + title + "</a></td>");
            sb.Append("                    <td align=\"center\" valign=\"top\" class=\"zt01\">" + pubDate + "</td>");
            sb.Append("                  </tr>");
            if (i % 5 == 4)
            {
                sb.Append("                  <tr>");
                sb.Append("                    <td height=\"11\" colspan=\"2\" align=\"left\" valign=\"top\" background=\"img/dot_line.gif\" class=\"zt07\"></td>");
                sb.Append("                  </tr>");
                sb.Append("");
            }
            #endregion
        }
        sb.Append("                </table>");
        sb.Append(cf.getPageHtml(CurrentPageNum, recordCount, pageSize, para));
        #endregion

        litNews.Text = sb.ToString(); 
        #endregion

    }
}
